package com.meta.platform.company.util;

import org.springframework.util.DigestUtils;

public class MD5Util {
    /**
     * MD5加密
     *
     * @param data
     *            待加密数据
     * @return byte[] 消息摘要
     *
     * @throws Exception
     */
    public static byte[] encodeMD5(String data) throws Exception {

        // 执行消息摘要
        return DigestUtils.md5Digest(data.getBytes());
    }

    /**
     * MD5加密
     *
     * @param data
     *            待加密数据
     * @return byte[] 消息摘要
     *
     * @throws Exception
     */
    public static String encodeMD5Hex(String data) {
        // 执行消息摘要
        return DigestUtils.md5DigestAsHex(data.getBytes());
    }

    public static void main(String[] args) {
        String beforSignParam =
                "platformCode=platform1&shopCode=shop1&timeStamp=1589515240000&bizData={\"data\":\"1223\"}&token=abc123";

        System.out.println(encodeMD5Hex(beforSignParam));
    }

}
